﻿using System;
using System.Collections.Generic;
using System.Linq;
using Tauren.Business.DLL.Employee;
using Tauren.Business.DLL.Resouces;
using Tauren.Business.DLL.Unitinfo;
using Tauren.Business.Entity.Config;
using Tauren.Business.Entity.Const;
using Tauren.Business.Entity.Enum;
using Tauren.Business.Entity.Global;
using Tauren.Business.Entity.Input;
using Tauren.Business.Entity.Model;
using Tauren.Business.Entity.Output;
using Tauren.Business.Infrastructure.Globals;
using Model = Tauren.Business.Entity.Model;

namespace Tauren.Business.Service.UnitInfo.V1
{
    public class UnitInfoService : UnitInfoImpBase
    {
        public IEmployeeBusiness employeeBusiness { get; set; }
        public UnitInfoService(IUnitinfoBusiness business, IConnectionBLLBase connectionBLL, IMenuResourcesBusiness menuResources) : base(business, connectionBLL, menuResources)
        {
            ResourcesInfo = GetResources(GlobalConst.RESOURCES_FLAG_MODULE_COMPANY_KEY);
            JudePrmission(GlobalConst.RESOURCES_FLAG_MODULE_COMPANY_KEY.ToLower());
            this.business = business;
        }

        private IUnitinfoBusiness business { get; set; }
        public override double Version => 1.0;
        /// <summary>
        /// 新增单位信息
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public override IResponseMessage Add(Unitinfo_Input input)
        {
            if (!HavePermission) return ErrorType.BUSINESS_WITHOUT_PERMISSION.Failure(CommonText(ErrorType.BUSINESS_WITHOUT_PERMISSION));
            Unitinfo model = null;
            ToModel(input, out model);
            if (model == null) return GlobalErrorType.GLOBAL_NOT_FOUND_INPUT_DATA.Failure(CommonText(GlobalErrorType.GLOBAL_NOT_FOUND_INPUT_DATA));
            model.Creatdate = DateTime.Now;
            model.Modifier = Global.EmpId;
            model.Creator = Global.EmpId;
            model.Modifdate = DateTime.Now;
            model.Enable = true;
            model.HaveDelete = false;
            var dbModel = business.GetByCode(model.UnitCode);
            if (dbModel == null)
            {
                if (!(input.Legals is null) && input.Legals.Any())
                {
                    model.Legal = input.Legals.FirstOrDefault().EmpId.ToString();
                }
                else
                {
                    model.Legal = "";
                }
                long id = business.Add(model);
                if (id > 0)
                {
                    return "".OnSucceed(CommonText(GlobalErrorType.GLOBAL_SAVE_SUCCESSINFO.ToString()));
                }
                else return GlobalErrorType.GLOBAL_SAVE_FAILURE.OnSucceed(CommonText(GlobalErrorType.GLOBAL_SAVE_FAILURE));
            }
            else return GlobalErrorType.GLOBAL_SAVE_FAILURE.OnSucceed(CommonText(GlobalErrorType.GLOBAL_SAVE_FAILURE));
        }

        /// <summary>
        /// 获取所有信息
        /// </summary>
        /// <returns></returns>
        public override IResponseMessage All()
        {
            List<Unitinfo> unitinfos = business.All<Unitinfo>();
            List<Unitinfo_OutPut> _OutPuts = new List<Unitinfo_OutPut>();
            ToViewModel(unitinfos, out _OutPuts);
            if (_OutPuts.Any())
            {
                _OutPuts.ForEach(o =>
                {
                    o.Dic_Creator = EmpDictionary.ContainsKey(o.Creator) ? EmpDictionary[o.Creator] : "";
                    o.Dic_Modifier = EmpDictionary.ContainsKey(o.Modifier) ? EmpDictionary[o.Modifier] : "";
                });
            }
            return _OutPuts.Succeed();
        }

        /// <summary>
        /// 删除单位信息
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public override IResponseMessage Delete(object id)
        {
            if (!HavePermission) return ErrorType.BUSINESS_WITHOUT_PERMISSION.Failure(CommonText(ErrorType.BUSINESS_WITHOUT_PERMISSION));
            Unitinfo unitinfo = business.Get<Unitinfo>(id);
            if (unitinfo == null) return GlobalErrorType.GLOBAL_NOT_FOUND_DB_DATA.Failure(CommonText(GlobalErrorType.GLOBAL_NOT_FOUND_DB_DATA));
            unitinfo.HaveDelete = true;
            unitinfo.Modifdate = DateTime.Now;
            unitinfo.Modifier = Global.EmpId;
            bool b = business.Update(unitinfo);
            if (b) return "".OnSucceed(Resources(GlobalErrorType.GLOBAL_DELETE_SUCCESSINFO));
            else return GlobalErrorType.GLOBAL_DELETE_FAILURE.OnSucceed(CommonText(GlobalErrorType.GLOBAL_DELETE_FAILURE));
        }

        /// <summary>
        /// 编辑单位信息
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public override IResponseMessage Edit(Unitinfo_Input input)
        {
            if (!HavePermission) return ErrorType.BUSINESS_WITHOUT_PERMISSION.Failure(CommonText(ErrorType.BUSINESS_WITHOUT_PERMISSION));
            Unitinfo model = null;
            ToModel(input, out model);
            if (model == null) return GlobalErrorType.GLOBAL_NOT_FOUND_INPUT_DATA.Failure(CommonText(GlobalErrorType.GLOBAL_NOT_FOUND_INPUT_DATA));
            model.Modifier = Global.EmpId;
            model.Modifdate = DateTime.Now;
            var dbModel = business.GetByCode(model.UnitCode);
            if (dbModel == null) return GlobalErrorType.GLOBAL_NOT_FOUND_DB_DATA.Failure(CommonText(GlobalErrorType.GLOBAL_NOT_FOUND_DB_DATA));
            model.UnitId = dbModel.UnitId;
            model.UnitCode = dbModel.UnitCode;
            model.Creatdate = dbModel.Creatdate;
            model.Creator = dbModel.Creator;
            if (!(input.Legals is null) && input.Legals.Any())
            {
                model.Legal = input.Legals.FirstOrDefault().EmpId.ToString();
            }
            else
            {
                model.Legal = "";
            }
            if (business.Update(model))
                return "".OnSucceed(CommonText(GlobalErrorType.GLOBAL_SAVE_SUCCESSINFO.ToString()));
            else return GlobalErrorType.GLOBAL_SAVE_FAILURE.OnSucceed(CommonText(GlobalErrorType.GLOBAL_SAVE_FAILURE));

        }

        public override IResponseMessage Enable(int id)
        {
            if (!HavePermission) return ErrorType.BUSINESS_WITHOUT_PERMISSION.Failure(CommonText(ErrorType.BUSINESS_WITHOUT_PERMISSION));
            Unitinfo unitinfo = business.Get<Unitinfo>(id);
            if (unitinfo == null) return GlobalErrorType.GLOBAL_NOT_FOUND_DB_DATA.Failure(CommonText(GlobalErrorType.GLOBAL_NOT_FOUND_DB_DATA));
            unitinfo.Enable = !unitinfo.Enable;
            unitinfo.Modifdate = DateTime.Now;
            unitinfo.Modifier = Global.EmpId;
            bool b = business.Update(unitinfo);
            if (b) return "".OnSucceed(CommonText(unitinfo.Enable ? GlobalErrorType.GLOBAL_ENABLE_SUCCESSINFO : GlobalErrorType.GLOBAL_DISABLE_SUCCESSINFO));
            else return unitinfo.Enable ? GlobalErrorType.GLOBAL_ENABLE_FAILURE.OnSucceed(CommonText(GlobalErrorType.GLOBAL_ENABLE_FAILURE)) : GlobalErrorType.GLOBAL_DISABLE_FAILURE.OnSucceed(CommonText(GlobalErrorType.GLOBAL_DISABLE_FAILURE));

        }

        public override IResponseMessage FirstOrDefault(object id)
        {
            Unitinfo unitinfo = business.Get<Unitinfo>(id);
            Unitinfo_OutPut _OutPut = new Unitinfo_OutPut();
            ToViewModel(unitinfo, out _OutPut);
            if (_OutPut is null) return new Unitinfo_OutPut().Succeed();
            if (!string.IsNullOrEmpty(unitinfo.Legal))
            {
                var legal = employeeBusiness.Get<Model.Employee>(int.Parse(unitinfo.Legal));
                if (!(legal is null))
                {
                    _OutPut.Legals = new List<PersonInfo_OutPut>() { new PersonInfo_OutPut() { EmpId = legal.EmpId, CNName = legal.CNName, ENName = legal.ENName } };
                }
            }
            return _OutPut.Succeed();
        }

        /// <summary>
        /// 根据编码获取单位信息
        /// </summary>
        /// </summary>
        /// <param name="model">单位信息实体</param>
        /// <returns></returns>
        public override IResponseMessage GetByCode(string Code)
        {
            Unitinfo unitinfo = business.GetByCode(Code);
            Unitinfo_OutPut _OutPut = new Unitinfo_OutPut();
            ToViewModel(unitinfo, out _OutPut);
            if (_OutPut != null)
            {
                _OutPut.Dic_Creator = ToSingeUserInfoName(_OutPut.Creator, Global.Language);
                _OutPut.Dic_Modifier = ToSingeUserInfoName(_OutPut.Modifier, Global.Language);
            }
            return _OutPut.Succeed();
        }

        /// <summary>
        /// 根据编码获取单位信息
        /// </summary>
        /// </summary>
        /// <param name="model">单位信息实体</param>
        /// <returns></returns>
        public override IResponseMessage GetByCodes(string[] Codes)
        {
            List<Unitinfo> unitinfos = business.GetByCode(Codes);
            List<Unitinfo_OutPut> _OutPuts = new List<Unitinfo_OutPut>();
            ToViewModel(unitinfos, out _OutPuts);
            if (_OutPuts.Any())
            {
                _OutPuts.ForEach(o =>
                {
                    o.Dic_Creator = EmpDictionary.ContainsKey(o.Creator) ? EmpDictionary[o.Creator] : "";
                    o.Dic_Modifier = EmpDictionary.ContainsKey(o.Modifier) ? EmpDictionary[o.Modifier] : "";
                });
            }
            return _OutPuts.Succeed();
        }
        /// <summary>
        /// 分页获取单位信息
        /// </summary>
        /// <param name="queryModel"></param>
        /// <returns></returns>
        public override IResponseMessage Pages(QueryModel queryModel)
        {
            if (!HavePermission) return ErrorType.BUSINESS_WITHOUT_PERMISSION.Failure(CommonText(ErrorType.BUSINESS_WITHOUT_PERMISSION));
            TableListModel<PageUnitInfoTable> tableListModel = new TableListModel<PageUnitInfoTable>();
            List<TableListHeaderModele> Headers = new List<TableListHeaderModele>();
            Headers.Add(new TableListHeaderModele() { Key = "rowNo", Name = CommonText("rowno"), Width = 50, Fixed = true });
            Headers.Add(new TableListHeaderModele() { Key = "unitId", Name = Resources("unitid"), Width = 120, Hide = true, Fixed = true });
            Headers.Add(new TableListHeaderModele() { Key = "unitCode", Name = Resources("unitcode"), Width = 120, Type = "primary_key", IsTag = true, SorTable = SortType.custom.ToString(), Align = "center", Fixed = true, Filter = true });
            Headers.Add(new TableListHeaderModele() { Key = "cnName", Name = Resources("cnname"), Type = "primary_name", IsOperation = true, SorTable = SortType.custom.ToString(), Fixed = true, Width = 260, Filter = true });
            Headers.Add(new TableListHeaderModele() { Key = "enName", Name = Resources("enname"), Type = "primary_name", SorTable = SortType.custom.ToString(), Width = 260, Filter = true, Fixed = true });
            Headers.Add(new TableListHeaderModele() { Key = "unitAddress", Name = Resources("unitaddress"), Width = 180, SorTable = SortType.custom.ToString(), Filter = true });
            Headers.Add(new TableListHeaderModele() { Key = "legal", Name = Resources("legal"), Width = 140, SorTable = SortType.custom.ToString(), Align = "center" });
            Headers.Add(new TableListHeaderModele() { Key = "contact", Name = Resources("contact"), Width = 160, Align = "center" });
            Headers.Add(new TableListHeaderModele() { Key = "phone", Name = Resources("phone"), Width = 160, Align = "center" });
            Headers.Add(new TableListHeaderModele() { Key = "dic_Enable", Name = CommonText("thstate"), IsTag = true, Width = 100, Align = "center", SorTable = SortType.custom.ToString() });
            Headers.Add(new TableListHeaderModele() { Key = "dic_Creator", Name = CommonText("diccreator"), Width = 120, Align = "center" });
            Headers.Add(new TableListHeaderModele() { Key = "dic_Creatdate", Name = CommonText("diccreatdate"), Width = 160, Align = "center" });
            Headers.Add(new TableListHeaderModele() { Key = "action", Name = "操作", Width = 180, Align = "center" });
            List<PageUnitInfoTable> unitListModels = new List<PageUnitInfoTable>();
            long Total = 0;
            List<PageUnitModel> pageUnitModels = business.Pages(queryModel, out Total);
            if (pageUnitModels.Any())
            {
                ToViewModels(pageUnitModels, out unitListModels);
                unitListModels.ForEach(o =>
                {
                    o.Dic_Enable = CommonText(o.Enable ? GlobalConst.RESOURCES_CONTENT_ENABLE_KEY : GlobalConst.RESOURCES_CONTENT_DISABLE_KEY);
                    o.Dic_Creator = EmpDictionary.ContainsKey(o.Creator) ? EmpDictionary[o.Creator] : "";
                    o.Dic_Modifier = EmpDictionary.ContainsKey(o.Modifier) ? EmpDictionary[o.Modifier] : "";
                    o.Dic_Creatdate = o.Creatdate.Value.ToString(GlobalConst.DATE_FORMAT_SECONDS);
                    o.Row_Style = o.Enable ? "" : "danger";
                    o.Operations = new List<SystemButton>();
                    o.Legal = string.IsNullOrEmpty(o.Legal) ? "" : EmpDictionary.ContainsKey(int.Parse(o.Legal)) ? EmpDictionary[int.Parse(o.Legal)] : "";
                    if (Global.IsAdmin && (Buttons is null || !Buttons.Any()))
                    {
                        BuliderButtons(o.Operations, o.UnitCode, o.UnitId, ButtomType.edit);
                        BuliderButtons(o.Operations, o.UnitCode, o.UnitId, ButtomType.detaile);
                        BuliderButtons(o.Operations, o.UnitCode, o.UnitId, !o.Enable ? ButtomType.enable : ButtomType.disable);
                        BuliderButtons(o.Operations, o.UnitCode, o.UnitId, ButtomType.delete);
                    }
                    else
                    {
                        if (Buttons.Any(o => o.Location == ButtomLocation.center.ToString() && o.Value == ButtomType.edit.ToString()))
                            BuliderButtons(o.Operations, o.UnitCode, o.UnitId, ButtomType.edit);
                        if (Buttons.Any(o => o.Location == ButtomLocation.center.ToString() && o.Value == ButtomType.detaile.ToString()))
                            BuliderButtons(o.Operations, o.UnitCode, o.UnitId, ButtomType.detaile);
                        if (Buttons.Any(o => o.Location == ButtomLocation.center.ToString() && (o.Value == ButtomType.disable.ToString() || o.Value == ButtomType.enable.ToString())))
                            BuliderButtons(o.Operations, o.UnitCode, o.UnitId, !o.Enable ? ButtomType.enable : ButtomType.disable);
                        if (Buttons.Any(o => o.Location == ButtomLocation.center.ToString() && o.Value == ButtomType.delete.ToString()))
                            BuliderButtons(o.Operations, o.UnitCode, o.UnitId, ButtomType.delete);
                    }
                });
            }
            tableListModel.Body = unitListModels;
            tableListModel.Total = Total;
            tableListModel.Header = Headers;
            if (Global.IsAdmin && (Buttons is null || !Buttons.Any()))
            {
                BuliderButtons(tableListModel.Operations, "", 0, ButtomType.add);
            }
            else
            {
                if (Buttons.Any(o => o.Value == ButtomType.add.ToString()))
                    BuliderButtons(tableListModel.Operations, "", 0, ButtomType.add);
            }
            return tableListModel.Succeed();
        }

        public override IResponseMessage Config(string PageType)
        {
            if (!HavePermission) return ErrorType.BUSINESS_WITHOUT_PERMISSION.Failure(CommonText(ErrorType.BUSINESS_WITHOUT_PERMISSION));
            List<OutPutConfig> Fields = new List<OutPutConfig>();

            OutPutConfig config = new OutPutConfig();
            config.Label = CommonText("autoId");
            config.FieldKey = "unitid";
            config.MenuCode = GlobalConst.RESOURCES_FLAG_MODULE_COMPANY_KEY.ToLower();
            config.ControlType = ControlType.number;
            Fields.Add(config);
            config = new OutPutConfig();
            config.Label = Resources("unitCode");
            config.FieldKey = "unitCode";
            config.MenuCode = GlobalConst.RESOURCES_FLAG_MODULE_COMPANY_KEY.ToLower();
            config.ControlType = ControlType.text;
            config.Show = true;
            config.Editor = PageType != "view" && PageType != "edit";
            config.Required = PageType != "view" && PageType != "edit";
            Dictionary<object, object> rule = new Dictionary<object, object>();
            if (PageType != "view")
            {
                #region 添加验证规则

                rule.Add("required", true);
                rule.Add("message", Resources("unitcoderequired"));
                rule.Add("trigger", "blur");
                config.Rules.Add(rule);
                ///长度
                rule = new Dictionary<object, object>();
                rule.Add("min", 1);
                rule.Add("max", 10);
                rule.Add("message", Resources("unitcodemax"));
                rule.Add("trigger", "blur");
                config.Rules.Add(rule);
                ///正则
                rule = new Dictionary<object, object>();
                rule.Add("pattern", "^([a-zA-Z0-9]){1,10}$");
                rule.Add("message", Resources("unitcoderegx"));
                rule.Add("trigger", "blur");
                config.Rules.Add(rule);
            }
            Fields.Add(config);
            #endregion
            #region 中文名
            config = new OutPutConfig();
            config.Label = Resources("cnName");
            config.FieldKey = "cnName";
            config.MenuCode = GlobalConst.RESOURCES_FLAG_MODULE_COMPANY_KEY.ToLower();
            config.ControlType = ControlType.textarea;
            config.Show = true;
            config.Editor = PageType != "view";
            config.Required = PageType != "view";
            rule = new Dictionary<object, object>();
            if (PageType != "view")
            {
                rule.Add("required", true);
                rule.Add("message", Resources("cnnamerequired"));
                rule.Add("trigger", "blur");
                config.Rules.Add(rule);
                ///长度
                rule = new Dictionary<object, object>();
                rule.Add("min", 1);
                rule.Add("max", 100);
                rule.Add("message", Resources("cnnamemax"));
                rule.Add("trigger", "blur");
                config.Rules.Add(rule);
            }
            Fields.Add(config);
            #endregion
            #region 英文名
            config = new OutPutConfig();
            config.Label = Resources("enName");
            config.FieldKey = "enName";
            config.MenuCode = GlobalConst.RESOURCES_FLAG_MODULE_COMPANY_KEY.ToLower();
            config.ControlType = ControlType.textarea;
            config.Show = true;
            config.Editor = PageType != "view";
            config.Required = PageType != "view";
            rule = new Dictionary<object, object>();
            if (PageType != "view")
            {
                rule.Add("required", true);
                rule.Add("message", Resources("ennamerequired"));
                rule.Add("trigger", "blur");
                config.Rules.Add(rule);
                ///长度
                rule = new Dictionary<object, object>();
                rule.Add("min", 1);
                rule.Add("max", 200);
                rule.Add("message", Resources("ennamemax"));
                rule.Add("trigger", "blur");
                config.Rules.Add(rule);
            }
            Fields.Add(config);
            #endregion
            ///法人
            config = new OutPutConfig();
            config.FieldKey = "legals";
            config.MenuCode = GlobalConst.RESOURCES_FLAG_MODULE_COMPANY_KEY.ToLower();
            config.ControlType = ControlType.employee;
            config.SelectType = SelectType.radio;
            config.Label = Resources("legal");
            config.Show = true;
            config.Editor = PageType != "view";
            BuliedTableConfig(config.Tables, PageType, new List<FromTableHeader>() { new FromTableHeader { FieldKey = "empId", Show = false, Primary = true }, new FromTableHeader { FieldKey = "cnName" }, new FromTableHeader { FieldKey = "enName" } }, config.Operations);
            Fields.Add(config);
            #region 联系方式
            config = new OutPutConfig();
            config.Label = Resources("unitAddress");
            config.FieldKey = "unitAddress";
            config.MenuCode = GlobalConst.RESOURCES_FLAG_MODULE_COMPANY_KEY.ToLower();
            config.ControlType = ControlType.text;
            config.Show = true;
            config.Editor = PageType != "view";
            config.Required = PageType != "view";
            Fields.Add(config);

            config = new OutPutConfig();
            config.Label = Resources("contact");
            config.FieldKey = "contact";
            config.MenuCode = GlobalConst.RESOURCES_FLAG_MODULE_COMPANY_KEY.ToLower();
            config.ControlType = ControlType.text;
            config.Show = true;
            config.Editor = PageType != "view";
            config.Required = PageType != "view";
            Fields.Add(config);

            config = new OutPutConfig();
            config.Label = Resources("phone");
            config.FieldKey = "phone";
            config.MenuCode = GlobalConst.RESOURCES_FLAG_MODULE_COMPANY_KEY.ToLower();
            config.ControlType = ControlType.text;
            config.Show = true;
            config.Editor = PageType != "view";
            config.Required = PageType != "view";
            Fields.Add(config);
            #endregion
            return Fields.Succeed();
        }

        public override IResponseMessage Tree()
        {
            if (!HavePermission) return ErrorType.BUSINESS_WITHOUT_PERMISSION.Failure(CommonText(ErrorType.BUSINESS_WITHOUT_PERMISSION));
            List<TreeCompany_OutPut> _OutPuts = new List<TreeCompany_OutPut>();
            List<Unitinfo> unitinfos = business.All<Unitinfo>();
            unitinfos.Where(u => u.ParentId == 0 && !u.HaveDelete).ToList().ForEach(o =>
              {
                  _OutPuts.Add(new TreeCompany_OutPut()
                  {
                      Icon = "",
                      Id = o.UnitId,
                      Label = Global.Language == LanguageType.zh_cn.ToString().Replace("_", "-") ? o.CNName : string.IsNullOrEmpty(o.ENName) ? o.CNName : o.ENName,
                      Code = o.UnitCode,
                      CNName = o.CNName,
                      ENName = o.ENName,
                      UnitId = o.UnitId,
                      Contact = o.Contact,
                      Phone = o.Phone,
                      ParentId = o.ParentId.Value,
                      UnitAddress = o.UnitAddress,
                      UnitCode = o.UnitCode,
                      Children = GenerateChildTreeInfo(o.UnitId, unitinfos),
                      UseNodeCss = !o.Enable || o.HaveDelete,
                      Level = o.Level
                  });
              });
            return _OutPuts.Succeed();
        }
        /// <summary>
        /// 递归获取子菜单
        /// </summary>
        /// <param name="ParentCode"></param>
        /// <param name="menus"></param>
        /// <returns></returns>
        private List<TreeCompany_OutPut> GenerateChildTreeInfo(int ParentId, List<Unitinfo> unitinfos)
        {
            List<TreeCompany_OutPut> _OutPuts = new List<TreeCompany_OutPut>();
            List<Unitinfo> childMenus = unitinfos.Where(o => !o.HaveDelete && o.ParentId == ParentId).ToList();
            if (childMenus.Any())
            {
                _OutPuts = new List<TreeCompany_OutPut>();
                childMenus.ForEach(o =>
                {
                    _OutPuts.Add(new TreeCompany_OutPut()
                    {
                        Icon = "",
                        Id = o.UnitId,
                        Label = Global.Language == LanguageType.zh_cn.ToString().Replace("_", "-") ? o.CNName : string.IsNullOrEmpty(o.ENName) ? o.CNName : o.ENName,
                        Code = o.UnitCode,
                        CNName = o.CNName,
                        ENName = o.ENName,
                        UnitId = o.UnitId,
                        Contact = o.Contact,
                        Phone = o.Phone,
                        ParentId = o.ParentId.Value,
                        UnitAddress = o.UnitAddress,
                        UnitCode = o.UnitCode,
                        Children = GenerateChildTreeInfo(o.UnitId, unitinfos),
                        UseNodeCss = !o.Enable || o.HaveDelete,
                        Level = o.Level
                    });
                });
            }
            return _OutPuts;
        }
    }
}
